package com.bigstonecontainer.training.springboot.frm.server.core.exception;

import com.bigstonecontainer.training.springboot.frm.server.core.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ControllerAdvice
@Slf4j
public class FrmServerControllerAdvice {

    @ExceptionHandler(FrmServerException.class)
    public Result handleFrmServerException(FrmServerException ex) {
        log.error(ex.getMessage(), ex);
        return ex.getResult();
    }

    @ExceptionHandler(Exception.class)
    public Result handleOtherExceptions(Exception ex) {
        log.error(ex.getMessage(), ex);
        return Result.error(ex.getMessage());
    }
}
